package com.namecard.namecardapi.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.namecard.namecardapi.entity.vo.TagVO;
import com.namecard.namecardapi.mapper.TagInfoMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author wzx
 */
@Component
public class TagUtil {

    @Resource
    TagInfoMapper tagInfoMapper;

    public List<TagVO> getTagList(String tagList){
        JSONArray objects = JSON.parseArray(tagList);
        // 封装的标签集合
        return objects.stream()
                .parallel()
                .filter(Objects::nonNull)
                .map(tagId -> tagInfoMapper.getTagContent(Long.valueOf(String.valueOf(tagId))))
                .collect(Collectors.toList());
    }
}
